
;;
;;在特定模式下粘贴自动缩进
(defadvice yank (after indent-region activate)
  "To make yank content indent automatically."
  (if (member major-mode '(emacs-lisp-mode
                           scheme-mode
                           lisp-mode
                           lisp-interaction-mode
                           c-mode
                           c++-mode
                           objc-mode
                           latex-mode
                           plain-tex-mode))
      (indent-region (region-beginning) (region-end) nil)))

;; --- 自动对 C 语言的类型定义识别并进行语法加亮
;;(ctypes-auto-parse-mode 1)

;;解决缩进为8个字符问题
(setq-default tab-width 4)
;;编程时缩进为4个字符（默认为2个字符，在c，c++编程是，默认2个字符很难看）
;;参考资料: emacs中cc-mode的缩进配置方法详解
;; http://hi.baidu.com/susdisk/item/4a33cd87e45b74dfd0f8cd32
(setq c-basic-offset 4)

(c-set-offset 'inline-open())                   ;;写java时，函数完成后ret后，默认不缩进
(c-set-offset 'case-label() 1)                  ;; switch case 缩进方式

(c-add-style "microsoft"
			 '("stroustrup"
			   (c-offsets-alist
				(innamespace . -)
				(inline-open . 0)
				(inher-cont . c-lineup-multi-inher)
				(arglist-cont-nonempty . +)
				(template-args-cont . +))))

(c-add-style "myCppStyle"
			 '("linux"
			   (c-offsets-alist
				(innamespace . -)
				(inline-open . 0)
				(inher-cont . c-lineup-multi-inher)
				(arglist-cont-nonempty . +)
				(template-args-cont . +))))

(setq c-default-style "myCppStyle")



(require 'google-c-style)

(setq c-default-style "linux")
;; (add-hook 'c-mode-common-hook 'google-set-c-style)
;; (add-hook 'c-mode-common-hook 'google-make-newline-indent)


(setq-default fci-rule-column 80)
(setq whitespace-style '(face trailing))

(defun myEditMode()
  (linum-mode t)
  (hs-minor-mode t)
  )

(defun myShellMode()
  (local-set-key "\C-x b" 'ido-switch-buffer)
  (local-set-key "\C-o" 'find-file)
  )
(defun my-asm-mode-hook ()
  ;; you can use `comment-dwim' (M-;) for this kind of behaviour anyway
  (local-unset-key (vector asm-comment-char))
  ;; asm-mode sets it locally to nil, to "stay closer to the old TAB behaviour".
  (setq tab-always-indent (default-value 'tab-always-indent)))


;; (defun irony-enable ()
;;   "Start irony mode."
;;   (interactive)
;;   (semantic-mode 0)
;;   (remove-hook 'c++-mode-hook 'company-c-headers-setup)
;;   (remove-hook 'c-mode-hook 'company-c-headers-setup)
;;   (remove-hook 'c++-mode-hook 'company-semantic-setup)
;;   (remove-hook 'c-mode-hook 'company-semantic-setup)
;;   (rtags-start-process-unless-running)
;;   (add-hook 'c++-mode-hook 'company-rtags-setup)
;;   (add-hook 'c-mode-hook 'company-rtags-setup)
;;   (add-hook 'c++-mode-hook 'flycheck-rtags-setup)
;;   (add-hook 'c-mode-hook 'flycheck-rtags-setup)
;;   )


;; (remove-hook 'c++-mode-hook 'company-rtags-setup)
;; (remove-hook 'c-mode-hook 'company-rtags-setup)
;; (remove-hook 'c++-mode-hook 'flycheck-rtags-setup)
;; (remove-hook 'c-mode-hook 'flycheck-rtags-setup)

;;(cedet-enable)
(defun  cedet-enable()
  "Start CEDET."
  (interactive)
  (semantic-mode 1)
  )

(defun myAsmMode()
  (linum-mode t)
  (my-asm-mode-hook)
  )
(defun myCEditMode()
  (myEditMode)
  (semantic-mode 1)
  (company-mode 1)
  )

(add-hook 'asm-mode-hook 'myAsmMode)
(add-hook 'c-mode-common-hook 'myCEditMode)
(add-hook 'python-mode-hook 'myEditMode)
(add-hook 'sh-mode-hook 'myShellMode)
(add-hook 'java-mode-hook 'myEditMode)
(add-hook 'cmake-mode-hook 'myEditMode)
(add-hook 'emacs-lisp-mode-hook 'myEditMode)
(add-hook 'makefile-gmake-mode 'myEditMode)
(add-hook 'makefile-mode 'myEditMode)
(add-hook 'term-mode-hook 'myShellMode)
(provide 'programing)
